/**
 * Created by Administrator on 15-10-9.
 */
window.onload=function(){
    var id=$.getUrlParam("id");
    var url = getUrl();
    var userid=getUserId();
    var pager = 1;
    $.jsonp({
        url: 'http://'+url+'/api/user/user_cluck_list',
        data: {userId:id,pager:pager},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            //console.log(data);
            $.each(data.arrays,function(index,ele){
                var sex="female";
                if(ele.sex==1)
                    sex="male";
                var html='<li>' +
                    '<div class="order-list-avatar">' +
                    '<img src="'+ele.photo+'" alt="">' +
                    '</div>' +
                    '<div class="order-list-intro">' +
                    '<div class="order-list-intro-text">' +
                    '<p class="color666 fz14">'+ele.nickName+'</p>' +
                    '<p class="color666 fz14"><span class="sex sex-'+sex+' no-left"><i class="icons-sex-'+sex+'"></i>'+ele.age+'</span></p>' +
                    '</div>' +
                    '<div class="order-list-intro-button w_abc">' +
                    '<a data-gz="'+ele.cluckId+'" a href="javascript:void(0); "class="edit"style=" color:#c5c5c5; border:1px solid #c5c5c5;">已关注</a>' +
                    '</div>' +
                    '</div>' +
                    '</li>';
                $("#tdgz").append(html);
                if(data.arrays.length<15){
                    $(".load-mor").text("");
                    return;
                }
            })


            //判断是否关注
            var tadeuserid=id;
            $.jsonp({
                url: 'http://'+url+'/api/user/user_cluck_list',
                data: {userId:id},
                callbackParameter: "callback",
                success: function (data,textStatus,xOptions) {
                    $.each(data.arrays,function(index,ele){
                        if(ele.cluckId==tadeuserid){
                            $(".edit").text("已关注").css({'color': '#c5c5c5','border':'1px solid #c5c5c5'});
                        }
                    });
                    $(".edit").show();
                },
                error: function (xOptions, textStatus) {
                }

            });
        },
        error: function (xOptions, textStatus) {

        }
    });

    $(document).on('click','.edit',function(){
        var userId=$(this).data('gz');
        var _txt=$(this).text();
        var obtn=this;
        $.jsonp({
            url: 'http://'+url+'/api/user/cluck_user-'+userId,
            data: {userId:id},
            callbackParameter: "callback",
            success: function (data, textStatus, xOptions) {
                //console.log(data);
                var code = data.code;
                if(code==1) {
                    $(obtn).removeClass("btn").text("已关注").css({color: '#c5c5c5', 'border': '1px solid #c5c5c5'});
                    showToast("关注成功");
                }else{
                    $(obtn).addClass("btn").text("+关注").css({color: '#00a5e0', width: '60px', height: '30px', 'padding':'0','border':'1px solid #00a5e0'});
                    showToast("取消关注成功")
                }
            },
            error: function (xOptions, textStatus) {
            }
        });
    })
    $(".load-mor").on("click",function() {
        pager = pager + 1;
        $.jsonp({
            url: 'http://'+url+'/api/user/user_cluck_list',
            data: {userId:id,pager:pager},
            callbackParameter: "callback",
            success: function (data, textStatus, xOptions) {
                //console.log(data);
                $.each(data.arrays,function(index,ele){
                    var sex="female";
                    if(ele.sex==1)
                        sex="male";
                    var html='<li>' +
                        '<div class="order-list-avatar">' +
                        '<img src="'+ele.photo+'" alt="">' +
                        '</div>' +
                        '<div class="order-list-intro">' +
                        '<div class="order-list-intro-text">' +
                        '<p class="color666 fz14">'+ele.nickName+'</p>' +
                        '<p class="color666 fz14"><span class="sex sex-'+sex+' no-left"><i class="icons-sex-'+sex+'"></i>'+ele.age+'</span></p>' +
                        '</div>' +
                        '<div class="order-list-intro-button w_abc">' +
                        '<a data-gz="'+ele.cluckId+'" a href="javascript:void(0); "class="edit"style=" color:#c5c5c5; border:1px solid #c5c5c5;">已关注</a>' +
                        '</div>' +
                        '</div>' +
                        '</li>';
                    $("#tdgz").append(html);
                    if(data.arrays.length<15){
                        $(".load-mor").text("");
                        return;
                    }
                })
            },

            error: function (xOptions, textStatus) {

            }
        });
    });
}